﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Dinner.Models
{
	public class MenuRepository
	{
		private DinnerDataContext db = new DinnerDataContext(); 

		public IQueryable<Menu> FindAllMenus()
		{
			return db.Menus;
		}

		public IQueryable<Menu> FindUpcomingMenus()
		{
			return from menu in db.Menus
				   where menu.date > DateTime.Now
				   orderby menu.date
				   select menu;
		}

		public Menu GetMenu(int id)
		{
			return db.Menus.SingleOrDefault(m => m.menu_id == id);
		}

		public void Add(Menu menu)
		{
			db.Menus.InsertOnSubmit(menu);
		}

		public void Delete(Menu menu)
		{
			db.MenuItems.DeleteAllOnSubmit(menu.MenuItems);
			db.MenuOrders.DeleteAllOnSubmit(menu.MenuOrders);
			db.Menus.DeleteOnSubmit(menu);
		}

		public void Save()
		{
			db.SubmitChanges();
		}
	}
}
